<template>
  <Page class="authorize-form">
    <div class="authorize-body">
      <van-form ref="zxForm" validate-trigger="onBlur">
        <!-- 区域2 -->
        <div class="title">
          <span>上传身份证信息</span>
        </div>
        <van-field name="uploader" label="身份证正面">
          <template #input>
            <van-uploader v-model="form.imgDataPre" :max-count="1" />
          </template>
        </van-field>
        <!-- @click="openBank2" -->
        <van-field name="uploader" label="身份证反面">
          <template #input>
            <van-uploader v-model="form.imgDataBack" :max-count="1" />
          </template>
        </van-field>
        <!-- 区域1 -->
        <div class="title">
          <span>身份认证</span>
        </div>
        <div>
          <van-field
            label-width="140"
            v-model="form.name"
            required
            name="name"
            label="姓名"
            placeholder="请输入法人姓名"
            :rules="name"
            input-align="right"
            disabled
          />
          <van-field
            label-width="140"
            v-model="form.sex"
            required
            name="sex"
            label="性别"
            placeholder="请输入法人性别"
            :rules="sex"
            input-align="right"
            disabled
          />

          <van-field
            label-width="140"
            v-model="form.nationality"
            name="nationality"
            label="民族"
            required
            :rules="nationality"
            placeholder="请输入民族"
            input-align="right"
            disabled
          />
          <van-field
            readonly
            clickable
            name="datetimePicker"
            :value="form.birth"
            required
            label="出生日期"
            placeholder="出生日期"
            :rules="birth"
            @click="timeIsShow = true"
            input-align="right"
            disabled
          />
          <van-popup v-model="timeIsShow" position="bottom">
            <van-datetime-picker
              type="date"
              @confirm="csrqOnConfirm"
              @cancel="timeIsShow = false"
            />
          </van-popup>
          <van-field
            label-width="140"
            v-model="form.address"
            name="address"
            required
            label="地址"
            :rules="address"
            placeholder="请输入地址"
            input-align="right"
            disabled
          />
          <van-field
            label-width="140"
            v-model="form.issue_authority"
            name="issue_authority"
            label="公安局"
            :rules="issue_authority"
            required
            placeholder="请输入公安局"
            input-align="right"
            disabled
          />
          <!-- <van-field
            label-width="140"
            v-model="form.validate_date"
            name="validate_date"
            label="有效日期"
            placeholder="请输入有效日期"
            input-align="right"
          /> -->
          <van-field
            readonly
            clickable
            name="datetimePicker"
            :value="form.validate_date"
            label="有效期"
            required
            :rules="validate_date"
            placeholder="有效期"
            @click="yxqIsShow = true"
            input-align="right"
            disabled
          />
          <van-popup v-model="yxqIsShow" position="bottom">
            <van-calendar
              v-model="yxqIsShow"
              type="range"
              @confirm="yxsClick"
            />
          </van-popup>
        </div>
        <!-- 人脸认证按钮 -->
        <!-- <button
          class="theme-btn"
          style="margin: 22px auto"
          @click="goFace"
         loading-text="加载中..."
        >
          人脸认证
        </button> -->
        <div class="sumit_button">
          <van-button
            :loading="buttonLoading"
            round
            type="info"
            size="large"
            loading-text="加载中..."
              @click="goFace"
            >人脸认证</van-button
          >
        </div>
        <!-- <div class="autobook_div">
          <van-checkbox
            v-model="isreadchecked"
            disabled
            icon-size="22px"
            name="isreadchecked"
            :label-disabled="true"
            :rules="[{ required: true, message: '请先阅读授权书!' }]"
            @click="lookviewBookClick('2')"
            >我已阅读并同意</van-checkbox
          ><span class="autobook_span" @click="lookviewBookClick('2')"
            >《企业征信信息采集和查询授权书》</span
          >
        </div> -->
        <van-popup v-model="showPicker" position="bottom">
          <van-picker
            show-toolbar
            :columns="selectOptions"
            @confirm="onConfirm($event)"
            value-key="label"
            @cancel="showPicker = false"
          />
        </van-popup>
        <!-- <button
					class="theme-btn"
					style="margin: 22px auto"
					@click="nextStep"
					v-if="isLeafNode"
				>
					下一步
				</button> -->
      </van-form>
    </div>

    <!-- 企业基本户开户行 -->
    <transition name="bottomToTop05">
      <bankList
        ref="bankList"
        v-if="showBank1"
        @cancel="cancel1"
        :bankList="bankList1"
        @clickConfirm="clickConfirm1"
      ></bankList>
    </transition>
    <!-- 授权对象 -->
    <transition name="bottomToTop05">
      <bankList
        ref="bankList"
        v-if="showBank2"
        @cancel="cancel2"
        :bankList="bankList2"
        @clickConfirm="clickConfirm2"
      ></bankList>
    </transition>
    <!-- 日期选择 -->
    <van-popup v-model="authdateshowPicker" position="bottom">
      <van-datetime-picker
        type="date"
        title="选择年月日"
        @confirm="authdateConfirm"
        @cancel="authdateshowPicker = false"
        :min-date="minDate"
        :max-date="maxDate"
      />
    </van-popup>
    <!-- pdf -->
    <transition name="bottomToTop05">
      <view-pdf
        :pdfUrl="pdfUrl"
        :viewType="viewType"
        v-if="pdfIsShow"
        :isView="isView"
        @agreePdf="agreePdf"
      ></view-pdf>
    </transition>
    <!-- <button class="theme-btn" :class="{ disabled: canSub }" @click="submitForm">人脸认证</button> -->
    <div class="zhe-face" v-if="canLookFace">
      <van-loading size="24px" text-color="#0094ff" color="#0094ff" vertical
        >正在认证中，请稍后...</van-loading
      >
    </div>
    <div class="zhe-face1" v-if="cydn_loading">
      <van-loading
        size="44px"
        text-color="#fff"
        color="#fff"
        vertical
      ></van-loading>
    </div>
  </Page>
</template>

<script>
import bankList from "@/components/authorize/bankList";
import {
  getOrderedBanks,
  getCorpNames,
  faceRecognition,
  faceRecognition_face,
  insertMes,

  selectAuthDeptList,
  generateAuthorization_zx,
  allOpenBankList,
  allBankList,
  jbxxList,
  addOnlineAuth,
  idCardRecognition,
  id_number,
} from "@/interfaces/authorize";
import { token_cydn } from "@/interfaces/cydnQt";
import viewPdf from "@/components/authorize/viewPdf.vue";

export default {
  name: "authorize",
  components: {
    bankList,
    viewPdf,
  },
  data() {
    return {
      buttonLoading: false,
      timeIsShow: false,
      yxqIsShow: false,
      // 征信form表单
      form: {
        name: "",
        sex: "",
        nationality: "",
        birth: "",
        address: "",
        issue_authority: "",
        validate_date: "",
        imgDataPre: [],
        imgDataBack: [],
        id_number: "",
        PrePath: "",
        backPath: "",
      },
      // 微风企科技form表单
      wfFormList: [], // 动态表单
      wfForm: {
        // taxpayerId: '', // 纳税人识别号
      },
      nextWfForm: [], // 下一步的动态表单用于拼接
      wfRules: {}, // 规则
      treeId: "", // 模板id
      selectOptions: [], // 下拉内容
      applyInstr: "",
      selectBanklist2: [],
      bankList1: [],
      bankList2: [],
      showBank1: false,
      showBank2: false,
      radio: "0",
      bossList: [],
      showSearch: false,
      countdown: 0,
      countdownInterval: null,
      authdateshowPicker: false,
      minDate: "",
      maxDate: "",
      pdfIsShow: false, // 查看pdf
      isccancelpdf: false, // 是否可以关闭pdf
      isreadchecked: false, // 是否阅读了
      isLeafNode: false, // 是否展示下一步
      showFace: false, // 是否展示人脸按钮
      pdfUrl: "",
      isView: "2", // 是否阅读了，1是已阅读
      showPicker: false, // 下拉框的选择
      viewType: "",
      sqInfo: "",
      // 校验身份证号
      PersonIdRules: [
        {
          required: true,
          message: "法人身份证号不能为空",
          trigger: "onBlur",
        },
      ],
      name: [
        {
          required: true,
          message: "姓名不能为空",
          trigger: "onBlur",
        },
      ],
      sex: [
        {
          required: true,
          message: "性别号不能为空",
          trigger: "onBlur",
        },
      ],
      nationality: [
        {
          required: true,
          message: "民族信息不能为空",
          trigger: "onBlur",
        },
      ],
      birth: [
        {
          required: true,
          message: "出生日期不能为空",
          trigger: "onBlur",
        },
      ],
      address: [
        {
          required: true,
          message: "地址不能为空",
          trigger: "onBlur",
        },
      ],
      issue_authority: [
        {
          required: true,
          message: "公安局信息不能为空",
          trigger: "onBlur",
        },
      ],
      validate_date: [
        {
          required: true,
          message: "有效期不能为空",
          trigger: "onBlur",
        },
      ],

      times: "",
      canLookFace: false,
      isSuccess: "",
      showFaceBtn: false,
      cydn_loading: false,
      area: "",
      araeJC: "zj",
    };
  },
  computed: {
    canSub() {
      return Object.values(this.form).some((val) => !val);
    },
  },
  created() {
    let source = this.getUrlParam("source");
    let userId = this.getUrlParam("userId");
    localStorage.setItem("qyrz_source", source);
    localStorage.setItem("qyrz_userId", userId);
    console.log(source, userId, "有没有");
    const area = this.getUrlParam("area");
 

  
   
  },
  watch: {
    "form.imgDataPre"(newval, oldval) {
      console.log(newval, "我看看怎个回事1");
      this.getImgDataPre(newval);
    },
    "form.imgDataBack"(newval, oldval) {
      console.log(newval, "我看看怎个回事2");
      this.getImgBac(newval);
    },
   
  },
  destroyed() {
    clearInterval(this.countdownInterval);
  },
  methods: {
    formatDateRange(dateStrings) {
      // 将字符串转换为Date对象数组
      const dates = dateStrings.map((dateString) => new Date(dateString));

      // 找到最早和最晚的日期
      const startDate = new Date(
        Math.min(...dates.map((date) => date.getTime()))
      );
      const endDate = new Date(
        Math.max(...dates.map((date) => date.getTime()))
      );

      // 格式化日期
      function formatDate(date) {
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, "0");
        const day = String(date.getDate()).padStart(2, "0");
        return `${year}.${month}.${day}`;
      }

      // 返回格式化后的日期范围
      return `${formatDate(startDate)}-${formatDate(endDate)}`;
    },
    formatDate(dateString) {
      const date = new Date(dateString);

      // 确保日期是有效的
      if (isNaN(date.getTime())) {
        return "Invalid date";
      }

      // 手动格式化日期
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, "0"); // 月份从0开始
      const day = String(date.getDate()).padStart(2, "0");
      const hours = String(date.getHours()).padStart(2, "0");
      const minutes = String(date.getMinutes()).padStart(2, "0");
      const seconds = String(date.getSeconds()).padStart(2, "0");

      return `${year}年${month}月${day}日`;
    },
    getImgDataPre(data) {
      console.log(data, "拿到了");
      const info = new FormData();
      info.append("file", data[0].file);
      idCardRecognition(info).then((res) => {
        console.log(res, "调接口了");
        if (res.code == 200) {
          this.form.address = res.data.address;
          this.form.birth = res.data.birth;
          this.form.name = res.data.name;
          this.form.nationality = res.data.nationality;
          this.form.sex = res.data.sex;
          this.form.id_number = res.data.id_number;
          this.form.PrePath = res.data.tmpPath;
          console.log(this.form, "成了吗");
        }
      });
    },
    getImgBac(data) {
      console.log(data, "拿到了");
      const info = new FormData();
      info.append("file", data[0].file);
      idCardRecognition(info).then((res) => {
        console.log(res, "调接口了");
        if (res.code == 200) {
          this.form.issue_authority = res.data.issue_authority;
          this.form.validate_date = res.data.validate_date;
          this.form.backPath = res.data.tmpPath;
          console.log(this.form, "成了吗2");
        }
      });
    },
    csrqOnConfirm(e) {
      console.log(e, "eeee");
      let date = this.formatDate(e);
      this.form.birth = date;
      this.timeIsShow = false;
      console.log(date, "转换后的日期");
    },
    yxsClick(e) {
      console.log(e, "eee");
      let date = this.formatDateRange(e);
      console.log(date, "转换成功");
      this.form.validate_date = date;
      this.yxqIsShow = false;
    },
  
  
    // 有#的情况
    getQueryStringhash(key) {
      let after = window.location.search;
      if (after.indexOf("?") === -1) return null; //如果url中没有传参直接返回空
      //key存在先通过search取值如果取不到就通过hash来取
      after = after.substr(1) || window.location.hash.split("?")[1];
      if (after) {
        let reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
        let r = after.match(reg);
        if (r != null) {
          return decodeURIComponent(r[2]);
        } else {
          return null;
        }
      }
    },
    getUrlParam(name) {
      const queryStr = String(window.location).split("?")[1] || "";
      name = encodeURIComponent(name);
      let arr = new RegExp("(^|&)" + name + "=([^&]*)(&|$)").exec(queryStr);
      if (arr) {
        return decodeURIComponent(RegExp.$2);
      } else {
        return "";
      }
    },

    openPopu(item) {
      // console.log(item, 'item');
      this.selectOptions = item.selectOptions;
      this.popuId = item.id;
      this.showPicker = true;
    },
    handleBlur(item) {
      // console.log(this.wfForm[item]);
      this.$forceUpdate();
    },
    agreePdf() {
      this.isView = "1";
      this.pdfIsShow = false;
      this.isreadchecked = true;
    },

    wfCompany() {
      // this.getBasicInfo();
    },
    authdateConfirm(value) {
      this.form.authdate = this.$dayjs(value).format("YYYY-MM-DD");
      this.authdateshowPicker = false;
    },
    async getBossList(timer) {
      // console.log(timer, 'timer');
      // this.showSearch = true
      const params = {
        name: this.form.corpName,
        area: this.area,
      };
      console.log(params, "params");
      const res = await jbxxList(params);
      console.log(res, "搜索的企业列表");
      if (this.timer === timer) {
        if (res.data.length > 0) {
          // if (res.data.length === 1) {
          //   this.form.corpName = res.data[0].corpName
          //   this.form.corpCredit = res.data[0].corpCredit
          // } else {
          res.data.forEach((ped) => {
            ped.viewName = this.deal(ped.d2CorpName);
          });
          this.showSearch = true;
          this.bossList = res.data;
          // }
          // console.log(this.bossList, 'bossList')
        } else {
          this.showSearch = false;
        }
      }
    },
    onConfirm($event) {
      // console.log($event);
      const e = this.popuId;
      this.wfForm[e] = $event.value;
      this.showPicker = false;
    },
    async taxationCir() {
      if (!this.hasAllPropertiesWithValues(this.wfForm)) return;
      this.canLookFace = true;
      const params = {
        ...this.wfForm,
        treeId: this.treeId,
        cburl: "",
      };
      console.log(params, "params");
      // 发票授权
      const res = await this.authorizeLogin(params);
      console.log(res, "发票授权");
      if (res.code == "200") {
        // 查询授权结果
        this.pollApi();
      } else {
        this.$toast(res.message);
      }
    },
    hasAllPropertiesWithValues(obj) {
      return Object.keys(obj).findIndex((pre) => !obj[pre]) === -1
        ? true
        : false;
    },
    async getBankList(name = "") {
      const params = {
        area: this.area,
      };
      console.log(params, "params");
      const res = await allOpenBankList(params);
      this.bankList1 = JSON.parse(JSON.stringify(res.data)).map((pre) => {
        return {
          bankId: pre.code,
          bankName: pre.name,
        };
      });
    },
    async getSqObj(name = "") {
      const params = {
        area: this.area,
      };
      const res = await allBankList(params);
      this.bankList2 = JSON.parse(JSON.stringify(res.data)).map((pre) => {
        return {
          bankId: pre.code,
          bankName: pre.name,
        };
      });
    },
    async handleGetVerificationCode(item) {
      // 根据type调用不同的sdk方法
      const sendType = {
        1: "sendCaptcha",
        2: "sendAuthCaptchaCodeSm",
        3: "sendAuthCaptchaCodeFp",
        4: "sendAuthCaptchaCodeTpass",
      };
      const type = sendType[item.sendSms.type];
      console.log(item, "item");
      if (this.countdown > 0) {
        return; // 如果倒计时还在进行中，则不执行获取验证码逻辑
      }
      // 执行获取验证码逻辑，例如发送请求到后端获取验证码
      const params = {
        password: this.wfForm.password,
        username: this.wfForm.username, // 身份证号码
        messageCountDown: item.sendSms.messageCountDown,
        // employees: this.wfForm.employees,
        apiUrl: item.sendSms.apiUrl,
        buttonLabel: item.sendSms.buttonLabel,
        type: item.sendSms.type,
      };
      const res = await this.sendSms(params, type);
      console.log(res, "res");
      if (res.code == "200") {
        // 开始倒计时
        this.countdown = +item.sendSms.messageCountDown;
        const _this = this;
        this.countdownInterval = setInterval(() => {
          this.countdown--;
          if (this.countdown === 0) {
            clearInterval(_this.countdownInterval); // 倒计时结束时清除定时器
          }
        }, 1000);
      } else {
        this.$toast(res.message);
      }
    },
    // 发送短信验证
    sendSms(params, apiName) {
      console.log(params, "短信验证");
      return new Promise((resolve, reject) => {
        authSdk[apiName](params).then((res) => {
          resolve(res);
        });
      });
    },
    // 获取授权基本信息
    getBasicInfo() {
      const params = {
        taxpayerId: this.wfForm.taxpayerId,
        channelCode: "51e2s",
      };
      console.log(params, "获取授权基本信息");
      return new Promise((resolve, reject) => {
        authSdk.getBasicInfo(params).then((res) => {
          resolve(res);
        });
      });
    },
    // 省份授权模板获取
    getAuthTemplate() {
      const params = {};
      console.log(params, "省份授权模板获取");
      return new Promise((resolve, reject) => {
        authSdk.getAuthTemplate(params).then((res) => {
          resolve(res);
        });
      });
    },

    // 获取身份信息
    getAuthIdentityInfo(params) {
      console.log(params, "获取身份信息");
      params.treeId = this.treeId;
      return new Promise((resolve, reject) => {
        authSdk.getAuthIdentityInfo(params).then((res) => {
          resolve(res);
        });
      });
    },
    // 打开授权书
    lookviewBookClick(item) {
      // 如果为1代表是动态生成的授权页面
      // 如果不为1则是pdf展示
      if (item === "1") {
        this.viewType = item;
        this.pdfUrl = this.sqInfo;
        this.pdfIsShow = true;
      } else {
        this.viewType = item;
        // this.pdfUrl = "/viewpdf.pdf";
        this.pdfUrl = `https://zx-1311146360.cos.ap-shanghai.myqcloud.com/face/${this.araeJC}.pdf`;
        this.pdfIsShow = true;
      }
    },
    deal(val) {
      if (this.form.corpName) {
        return val.replace(
          this.form.corpName,
          "<font style='color:#fd485e;'>" + this.form.corpName + "</font>"
        );
      } else {
        return val;
      }
    },
    // 选择某个企业
    async selectOne(item) {
      this.form.corpName = item.d2CorpName;
      this.form.corpCredit = item.corpKey;
      // this.form.corpCredit = '321234567891011121';
      // this.form.legalName = '张聪';
      this.form.legalName = item.d2LegalPer;
      this.showSearch = false;
    },

    // 微风企
    async initWf() {
      // 获取微风企科技授权基本信息
      this.wfForm.taxpayerId = this.form.corpCredit;
      const res = await this.getBasicInfo();
      console.log(res, "res");
      if (res.code === "200") {
        // 获取授权书
        this.sqInfo = res.data.taxAuthAgreement;
        const resTemplate = await this.getAuthTemplate();
        console.log(resTemplate, "resTemplate");
        // 获取动态表单value
        resTemplate.data.treeNode[0].card.keyValues
          .map((val) => val.id)
          .forEach((pre) => (this.wfForm[pre] = ""));
        console.log(this.wfForm, "wfForm");
        this.wfForm.taxpayerId = this.form.corpCredit;
        this.wfForm.companyName = this.form.corpName;
        // 模拟数据
        // this.wfForm.companyName = '江苏某某某某某有限公司';
        // this.wfForm.password = '12345678';
        // this.wfForm.username = '321234567891011121';
        // 获取规则
        this.wfRules = resTemplate.data.treeNode[0].rules;
        const ruleList = Object.values(this.wfRules);
        ruleList.forEach((pre) => {
          pre.forEach((pio) => {
            pio.trigger =
              pio.trigger === "blur"
                ? "onBlur"
                : pio.trigger === "change"
                ? "onChange"
                : pio.trigger;
          });
        });
        console.log(this.wfRules, "wfRules");
        // 取出动态表单数组
        this.wfFormList = resTemplate.data.treeNode[0].card.keyValues;
        this.wfFormList.forEach((pl) => {
          pl.required = resTemplate.data.treeNode[0].rules[pl.id][0].required;
        });
        // 模板id
        this.treeId = resTemplate.data.treeNode[0].id;
        console.log(this.treeId, "treeId");
        // 是否展示下一步
        this.isLeafNode = !resTemplate.data.treeNode[0].isLeafNode;
        this.showFace = resTemplate.data.treeNode[0].isLeafNode;
        // 下一步表单
        this.nextWfForm = this.isLeafNode
          ? resTemplate.data.treeNode[0].card.subNodes.card.keyValues
          : [];
        console.log(this.wfFormList, "wfFormList");
        // 特殊处理->身份信息固定为法定代表人
        this.wfFormList.forEach((pre) => {
          if (pre.id === "loginType") {
            pre.type = "input";
            pre.disabled = true;
            this.wfForm.loginType = "法定代表人";
          }
        });
        this.nextWfForm.forEach((pre) => {
          if (pre.id === "employees") {
            pre.type = "input";
            pre.disabled = true;
          }
        });
        console.log(this.nextWfForm, "nextWfForm");
      } else {
        this.$toast(res.message);
      }
    },

    cancel1() {
      this.showBank1 = false;
    },
    cancel2() {
      this.showBank2 = false;
    },
    clickConfirm1(item) {
      this.showBank1 = false;
      this.form.bankName = item.bankName;
      this.form.bankId = item.bankId;
    },
    clickConfirm2(item) {
      this.showBank2 = false;
      this.form.authobject = item.bankName;
      this.form.authobjectId = item.bankId;
    },
    nextStep() {
      if (!this.isreadchecked) {
        this.$toast("请先阅读授权书");
        return;
      }
      this.$refs.zxForm
        .validate()
        .then((result) => {
          console.log(this.form, "form");
          console.log(this.wfForm, "wfForm");
          this.nextWfStep(this.wfForm);
        })
        .catch((error) => {
          console.log(error, "error");
        });
    },
    // 微风授权登录
    authorizeLogin(params) {
      return new Promise((resolve, reject) => {
        authSdk.authorizeLogin(params).then((res) => {
          resolve(res);
        });
      });
    },
    goFace() {
      console.log("卡主了");

      if (
        !this.form.name ||
        !this.form.sex ||
        !this.form.nationality ||
        !this.form.birth ||
        !this.form.address ||
        !this.form.issue_authority ||
        !this.form.validate_date
      ) {
        return;
      }
      let enterpriseObj = JSON.parse(JSON.stringify(this.form));

      enterpriseObj.imgDataPre = enterpriseObj.PrePath;
      enterpriseObj.imgDataBack = enterpriseObj.backPath;
      console.log(enterpriseObj, "this.formthis.form2322");

      localStorage.setItem("enterpriseObj", JSON.stringify(enterpriseObj));
      this.cydnFace();
      // 首先判断是否阅读
      // if (this.isView === "1") {
      //   this.cydnFace();
      // } else {
      //   this.$toast("请先阅读授权书");
      // }
    },
    async pollApi() {
      this.times++;
      // 3、轮询查询授权的结果
      const resultWf = await this.getAuthrizeResult();
      console.log(resultWf, "轮询查询授权的结果");
      if (resultWf.code == "200") {
        // 授权成功
        this.canLookFace = false;
        this.$toast("发票授权成功");
        window.localStorage.removeItem("pageInfo");
      } else {
        // 再次查询
        if (this.times > 120) {
          this.canLookFace = false;
          this.$toast("发票授权失败，请完善信息");
          window.localStorage.removeItem("pageInfo");
        } else {
          const _this = this;
          setTimeout(() => {
            _this.pollApi();
          }, 1000);
        }
      }
    },
    // 获取授权结果
    getAuthrizeResult(params = {}) {
      return new Promise((resolve, reject) => {
        authSdk.getAuthrizeResult(params).then((res) => {
          resolve(res);
        });
      });
    },
    async zxFace() {
      let area = this.area;
      const params = {
        name: this.form.legalName,
        idNo: this.form.lagelPersonId,
        callBackUrl: `https://fintech-zscqzy.szjrgzjg.com/#/faceSingle?code=&orderNo=&h5faceId=&newSign=&area=${area}`,
        // callBackUrl:
        // 	'http://192.168.1.100:8989/#/attestation?code=&orderNo=&h5faceId=&newSign=',
      };
      console.log(param, "callBackUrl");
      const res = await faceRecognition(params);
      // const res = {
      // 	faceUrl: 'https://www.baidu.com'
      // 	// faceUrl: 'http://192.168.1.100:8989/#/attestation?code=&orderNo=&h5faceId=&newSign='
      // }
      console.log(res, "faceUrl");

      if (res && res.faceUrl) {
        // 保存微风需要的授权参数
        // localStorage.setItem(
        // 	'wfForm',
        // 	JSON.stringify({
        // 		...this.wfForm,
        // 		treeId: this.treeId,
        // 		cburl: '',
        // 	})
        // );
        // 保存页面数据
        localStorage.setItem(
          "pageInfo",
          JSON.stringify({ ...this.form, isView: this.isView, area: area })
        );
        window.location.href = res.faceUrl;
      } else {
        this.$toast("姓名和身份证号不匹配");
      }
    },
    async cydnFace() {
      console.log("到这里了吗");
      this.buttonLoading=true
      const params = {
        name: this.form.name,
        idNo: this.form.id_number,
        // callBackUrl:
        //   'https://fintech-zscqzy.szjrgzjg.com/#/faceSingle?code=&orderNo=&h5faceId=&newSign=',
        callBackUrl: `https://fintech-zscqzy.szjrgzjg.com/#/CertificationTrue?code=&orderNo=&h5faceId=&newSign=`,
      };
      console.log(params, "params");
      const res = await faceRecognition_face(params);
       this.buttonLoading=false
      // const res = {
      // 	faceUrl: 'https://www.baidu.com'
      // 	// faceUrl: 'http://192.168.1.100:8989/#/attestation?code=&orderNo=&h5faceId=&newSign='
      // }
      console.log(res, "新版人脸");
      if (res && res.faceUrl) {
 
        window.location.href = res.faceUrl;
      } else {
        this.$toast("姓名和身份证号不匹配");
      }
    },
    async nextWfStep(params) {
      // 获取身份信息
      const res = await this.getAuthIdentityInfo(params);
      if (res.code == "200") {
        console.log(res, "res获取身份信息");
        // 对employees下拉框进行赋值
        // const oneObj = this.nextWfForm.find((val) => val.id === 'employees');
        // oneObj.selectOptions = res.data.employees;
        // 找出法定代表人
        const oneObj = res.data.employees.find(
          (pre) => pre.value.indexOf("法定代表人") > -1
        );
        this.wfForm.employees = oneObj.value;
        this.wfFormList.push(...this.nextWfForm);
        this.isLeafNode = false;
        this.showFace = true;
        this.$forceUpdate();
      } else {
        this.$toast(res.message);
      }
    },
  
    openBank1() {
      this.showBank1 = true;
    },
    openBank2() {
      this.showBank2 = true;
    },
    changeSearch() {
      this.showSearch = true;
    },

    // 有#的情况
    getQueryStringhash(name) {
      const queryStr = String(window.location).split("?")[1] || "";
      name = encodeURIComponent(name);
      let arr = new RegExp("(^|&)" + name + "=([^&]*)(&|$)").exec(queryStr);
      if (arr) {
        return RegExp.$2;
      } else {
        return "";
      }
    },
  },
};
</script>
<style>
.van-field--error .van-field__control,
.van-field--error .van-field__control::placeholder {
  color: #c8c9cc;
}

.van-field__error-message {
  text-align: right;
}
</style>
<style lang="scss" scoped>
@import "@/assets/css/demo/index.scss";

.authorize-top {
  height: 139px;
  border: 0.5px solid transparent;
  background-image: url("https://zx-1311146360.cos.ap-shanghai.myqcloud.com/wx_h5/wx_h5_top.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;

  .authorize-top-title1 {
    margin: 40px 0 0 28px;
    font-size: 21px;
    font-family: Source Han Sans SC;
    font-weight: 500;
    color: #ffffff;
  }

  .authorize-top-title2 {
    margin: 6px 0 0 28px;
    font-size: 17px;
    font-family: Source Han Sans SC;
    font-weight: 500;
    color: #ffffff;
  }
}

.authorize-form {
  position: relative;
  padding-bottom: 20px;
  height: 100%;
  overflow-y: auto;

  // border: 1px solid red;
  .title {
    width: 100%;
    height: 30px;
    background-image: url("~img/authorize/titlebg.png");
    background-size: cover;
    padding-left: 38px;
    line-height: 30px;

    span {
      font-size: 14px;
      font-weight: 550;
      color: #5094eb;
    }
  }
}

input {
  background: none;
  outline: none;
  border: none;
  text-align: right;
}

input:focus {
  border: none;
}

.bank_input {
  width: 200px;
  // border: 1px solid #e0e1e5;
  // padding: 10px 10px;
  padding-right: 8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: flex-end;

  .right-img {
    width: 4px;
    height: 8px;
    // border: 1px solid red;
    // position: relative;
    // bottom: -5px;
  }

  .bank_tag {
    // margin-bottom: 7px;
    // margin-right: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #999999;
    // background: #f5f5f5;
    // height: 34px;
    padding: 0 5px;
    font-size: 14px;

    .bank-tag-icon {
      margin-left: 4px;
      font-size: 16px;
    }
  }
}

.selecttext {
  // width: 500rpx;
  height: 30px;
  line-height: 30px;
  text-align: right;
  color: #999999;
  font-size: 12px;
  font-family: Alibaba PuHuiTi;
  color: #999999;
}

.right-is {
  display: flex;
  justify-content: flex-end;
}

.search-body {
  position: absolute;
  top: 72px;
  right: 10px;
  width: 240px;
  max-height: 200px;
  // border: 1px solid red;
  background: #fff;
  z-index: 100;
  box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
  overflow-y: auto;
  padding-bottom: 10px;

  .search-item {
    margin: 4px 0 0 8px;
    font-size: 12px;
    font-family: Alibaba PuHuiTi;
    color: #999999;
  }
}

.linkman_input {
  width: 140px;
}

.description {
  // width: 90%;
  text-align: center;

  textarea {
    width: 90%;
    padding: 4px;
    font-size: 14px;
  }
}

.authdate_flex {
  display: flex;
  font-size: 12px;

  .left {
    margin-right: 5px;
    // background-color: #f4f4f4;
    border-radius: 2px;
    padding: 0 5px;
    color: #999999;
  }

  .right {
    background-color: #f4f4f4;
    border-radius: 2px;
    padding: 0 10px;
    color: #999999;
    margin-left: 5px;
    font-size: 12px;
    box-sizing: border-box;
  }
}

.yzm-btn {
  width: 80px;
  height: 22px;
  background: #5094eb;
  border-radius: 5px;
  color: #fff;
  margin-left: 5px;
  font-size: 12px;
  // border: none;
}

// button ::after {
//   border: none;
// }
.autobook_div {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  margin: 0px 10px;
  font-size: 12px;

  // border: 1px solid red;
  .autobook_span {
    color: #5094eb;
    cursor: pointer;
    position: relative;
    line-height: 20px;
    // top: -2px;
  }

  /deep/.van-checkbox__label--disabled {
    color: #333;
  }

  /deep/.van-checkbox__icon--checked .van-icon {
    color: #fff;
    background-color: #1989fa;
    border-color: #1989fa;
  }
}

.zhe-face {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  z-index: 999;
  background: rgba(82, 80, 80, 0.2);
  display: flex;
  justify-content: center;
  align-items: center;
}
.zhe-face1 {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  z-index: 999;
  background: rgba(82, 80, 80, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
}
.tip-success {
  margin: 50px auto;
  text-align: center;
  font-size: 20px;
  color: #1989fa;
}
.sumit_button {
  width: 90%;
  margin: auto;
  margin-top: 30px;
}
</style>
